package com.sanji.register;/**
 * Created by 杨其才 on 2017/5/26.
 *
 * @
 */

import com.sanji.register.model.User;
import com.sanji.register.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
 * @author yangqc
 *         User: yangqc
 *         Date: 2017/5/26
 *         Time: 17:37
 * @description
 * @since 1.0
 */
@Service
public class UserService {
	@Autowired
	private UserRepository userRepository;

	public void modifyUser(@PathVariable String userId, @RequestBody Map<String, String> reqMap) throws Exception {
		User user = userRepository.findOne(userId);
		if (user == null) {
			throw new NullPointerException("用户不存在");
		}
		if (null != reqMap.get("password")) {
			user.setPassword(reqMap.get("password"));
		}
		if (null != reqMap.get("name")) {
			user.setName(reqMap.get("name"));
		}
		if (null != reqMap.get("phone")) {
			user.setPhone(reqMap.get("phone"));
		}
		userRepository.save(user);
	}
}
